VERSION=$(shell grep -i '^version' config.yaml | sed 's/.*: *//')
NAME=$(shell basename `pwd`)
BASENAME_JA=$(shell basename `pwd`)_ja-${VERSION}
BASENAME_ALL=$(shell basename `pwd`)_all-${VERSION}

PROJECT=$(shell svn info | grep ^URL | sed 's/.*:\/\///' | sed 's/\.googlecode\.com.*//')
URL=$(shell svn info | grep ^URL | sed 's/.*URL: *//' | sed 's/\(\.googlecode\.com\/svn\/\).*/\1/')

all: 

make_tag:
	svn commit
	svn copy ${URL}trunk/ ${URL}tags/release_${VERSION} -m 'release ${VERSION}'

upload_google: dist_ja dist_all
	googlecode_upload.py -s 'Release ${VERSION} (TGZ)' -p $(PROJECT) /tmp/${BASENAME_ALL}.tgz
	googlecode_upload.py -s 'Release ${VERSION} (ZIP)' -p $(PROJECT) /tmp/${BASENAME_ALL}.zip
	googlecode_upload.py -s 'Release ${VERSION} for Japanese (TGZ)' -p $(PROJECT) /tmp/${BASENAME_JA}.tgz
	googlecode_upload.py -s 'Release ${VERSION} for Japanese (ZIP)' -p $(PROJECT) /tmp/${BASENAME_JA}.zip

dist_ja:
	rm -fr /tmp/${BASENAME_JA}*
	mkdir -p /tmp/${BASENAME_JA}/plugins /tmp/${BASENAME_JA}/mt-static/plugins
	cp -pbR . /tmp/${BASENAME_JA}/plugins/${NAME}
	mv /tmp/${BASENAME_JA}/plugins/${NAME}/LICENSE /tmp/${BASENAME_JA}
	mv /tmp/${BASENAME_JA}/plugins/${NAME}/INSTALL* /tmp/${BASENAME_JA}
	cp -pbR ../../mt-static/plugins/${NAME} /tmp/${BASENAME_JA}/mt-static/plugins/${NAME}
	find /tmp/${BASENAME_JA} -type d -name '.svn' | xargs rm -fr
	rm -f /tmp/${BASENAME_JA}/plugins/${NAME}/Makefile
	make -C /tmp/${BASENAME_JA}/mt-static/plugins/${NAME}/lib ja
	rm -f /tmp/${BASENAME_JA}/mt-static/plugins/${NAME}/lib/*.zip
	rm -f /tmp/${BASENAME_JA}/mt-static/plugins/${NAME}/lib/Makefile
	tar zcf /tmp/${BASENAME_JA}.tgz -C /tmp ${BASENAME_JA}
	(cd /tmp; zip -qr ${BASENAME_JA}.zip ${BASENAME_JA})

dist_all:
	rm -fr /tmp/${BASENAME_ALL}*
	mkdir -p /tmp/${BASENAME_ALL}/plugins /tmp/${BASENAME_ALL}/mt-static/plugins
	cp -pbR . /tmp/${BASENAME_ALL}/plugins/${NAME}
	mv /tmp/${BASENAME_ALL}/plugins/${NAME}/LICENSE /tmp/${BASENAME_ALL}
	mv /tmp/${BASENAME_ALL}/plugins/${NAME}/INSTALL* /tmp/${BASENAME_ALL}
	cp -pbR ../../mt-static/plugins/${NAME} /tmp/${BASENAME_ALL}/mt-static/plugins/${NAME}
	find /tmp/${BASENAME_ALL} -type d -name '.svn' | xargs rm -fr
	rm -f /tmp/${BASENAME_ALL}/plugins/${NAME}/Makefile
	make -C /tmp/${BASENAME_ALL}/mt-static/plugins/${NAME}/lib all
	rm -f /tmp/${BASENAME_ALL}/mt-static/plugins/${NAME}/lib/*.zip
	rm -f /tmp/${BASENAME_ALL}/mt-static/plugins/${NAME}/lib/Makefile
	tar zcf /tmp/${BASENAME_ALL}.tgz -C /tmp ${BASENAME_ALL}
	(cd /tmp; zip -qr ${BASENAME_ALL}.zip ${BASENAME_ALL})

